package dome_005;

import java.util.concurrent.TimeUnit;

/**
 * <p>Description: [volatile 关键字，是一个变量在多个线程间可见]</p>
 * Created on 2020/12/3
 *
 * @author <a href="mailto: 819712047@qq.com">谢振东 </a>
 * @version 1.0
 */
public class Dome005_02 {
    volatile boolean running = true;

    public void test() {
        System.out.println("test start.......");
        while (running) {
			try {
				TimeUnit.SECONDS.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
        }
        System.out.println("test end........");
    }

    public static void main(String[] args) {
        Dome005_02 dome005_02 = new Dome005_02();

        new Thread(dome005_02::test, "t1").start(); //JDK1.8新特性

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        dome005_02.running = false;
    }
}
